package com.syn.synold4s.repository;


import com.gaoyi.basemodule.apiresult.ApiResultData;
import com.gaoyi.basemodule.baseCallback.Callback;
import com.gaoyi.basemodule.baseCallback.OnResultListener;
import com.gaoyi.basemodule.baseUtil.GsonUtil;
import com.gaoyi.basemodule.baseUtil.OKHttpUtil;
import com.google.gson.reflect.TypeToken;
import com.syn.synold4s.bean.dto.ShortDto;

import java.lang.reflect.Type;
import java.util.List;

public class ComboRepository {
    public void combo(String typeKey, final OnResultListener onResultListener, Type typeofT) {
        OKHttpUtil.getInstance().getAsync(OKHttpUtil.NET_URL + "/api/utils/combos?typeKey=" + typeKey,
                new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        onResultListener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        onResultListener.onFails(e);
                    }
                }, typeofT);
    }

    public List<ShortDto> comboSync(String typeKey) {//
        String result = OKHttpUtil.getInstance().getSync(OKHttpUtil.NET_URL + "/api/utils/combos?typeKey=" + typeKey);
        if (result == null) {
            return null;
        }
        ApiResultData<List<ShortDto>> apiResultData = (ApiResultData<List<ShortDto>>) GsonUtil.getInstance().fromJson(result, new TypeToken<ApiResultData<List<ShortDto>>>() {
        }.getType());
        return apiResultData.getData();

    }
}
